#include <iostream>

using namespace std;
int main(){
    string a [] {"zero","one","two","three","four","five","six","seven","eight","nine"};
    int nums [] {0,1,2,3,4,5,6,7,8,9};
    string lis [3];
    string st;
    string mass;
    int itog = 0;
    bool is_in = false;
    int zn = 100;
    cout << "Please, enter numbers in words: ";
    getline(cin, st);
    int j = 0;
    for (char i:st){
        if (!(i == ' ')){
            mass += i;
        }
        else{
            if (j == 3){
                cout << "Wrong input!";
                return 0;
            }
            lis[j] = mass;
            mass = "";
            ++j;
        }
    }
    if (j >= 3){
        cout << "Wrong input!";
        return 0;
    }
    lis[j] = mass;
    mass = "";
    ++j;
    int ind = 0;
    
    
    for (string x1:lis){
        is_in = false;
        ind = 0;
        for (string x2:a){
            if (x1 == x2){
                is_in = true;
                itog += zn*nums[ind];
                
                zn /= 10;
                if (zn == 0){
                    zn = 1;
                }
                break;
            }
            ++ind;
        }
        
    }
    if (is_in == false){
        cout << "Wrong input!";
        return 0;
    }
    int res = 1;
    bool flag = true;
    int now_itog = itog;
    for (int j = itog-1; j > 1; --j){
        flag = true;
        now_itog = j;
        for (int i = now_itog-1; i > 1; --i){
            if (now_itog % i == 0){
                res = now_itog;
                flag = false;
                break;
            }
        }
        if (flag){
            res = now_itog;
            break;
        }
    }

    flag = true;
    for (int j = itog; j <= itog+itog-res+1; ++j){
        flag = true;
        now_itog = j;
        for (int i = now_itog-1; i > 1; --i){
            if (now_itog % i == 0){
                flag = false;
                break;
            }
        }
        if (flag){
            res = now_itog;
            break;
        }
    }
    cout << res;
}
